package com.yuanfeng.job.service.impl;

import com.yuanfeng.commoms.vo.order.StatisticsMonthVO;
import com.yuanfeng.job.mapper.OrderbaseMapper;
import com.yuanfeng.job.service.OdbRangeStatisticsJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName OdbRangeStatisticsJobServiceImpl
 * @Description
 * @Author hyq
 * @Date 2023/9/5 11:31
 * @Version 1.0
 **/
@Service
public class OdbRangeStatisticsJobServiceImpl implements OdbRangeStatisticsJobService {

    @Autowired
    private OrderbaseMapper orderbaseMapper;
    @Override
    public Integer queryOdbStatisticsMonthJobJob(String finishTime) {
        String isNotshopId = "";
        List<String> shopIdNo = orderbaseMapper.queryfranchisesType();

        // 查询odb_shop_franchises_type，避免一些店铺
        int a = 0;
        if (!(shopIdNo.size() == 0)) {
            for (String shopid : shopIdNo) {
                if (a == 0) {
                    isNotshopId += shopid;
                } else {
                    isNotshopId += "," + shopid;
                }
                a++;
            }
        }
        List<StatisticsMonthVO> res = orderbaseMapper.queryOdbStatisticsSeftport(isNotshopId,finishTime);// 自身交易
        List<StatisticsMonthVO> result = orderbaseMapper.queryOdbStatisticsRealport(isNotshopId,finishTime);// 真是交易
        for (StatisticsMonthVO b : res) {
            for (StatisticsMonthVO c : result) {
                if (b.getStatisticsTime().equals(c.getStatisticsTime())) {
                    b.setTurnoverReal(c.getTurnoverReal());
                    BigDecimal numreal=b.getTurnoverReal().add(b.getTurnoverSelf()) ;
                    b.setProportion(b.getTurnoverReal().divide(numreal,2,BigDecimal.ROUND_HALF_UP));
                    Integer count=orderbaseMapper.insertOdbStatisticsMonth(b);
                }
            }
        }

        return null;
    }
}
